<?php

namespace app\modules\Cruise\models;

use Yii;

/**
 * This is the model class for table "restaurant".
 *
 * @property integer $id
 * @property string $cruise_id
 * @property string $name
 * @property string $num
 * @property string $spend
 * @property string $ceil
 * @property string $desc
 * @property integer $status
 * @property integer $user_id
 * @property string $created_at
 * @property string $updated_at
 */
class Restaurant extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'restaurant';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cruise_id'], 'required'],
            [['status', 'user_id'], 'integer'],
            [['created_at', 'updated_at'], 'safe'],
            [['cruise_id'], 'string', 'max' => 11],
            [['name'], 'string', 'max' => 128],
            [['num', 'open_time'], 'string', 'max' => 16],
            [['spend', 'ceil'], 'string', 'max' => 64],
            [['en_name'], 'string', 'max' => 255],
            [['desc'], 'string', 'max' => 512],
        ];
    }


    // 保存前处理
    public function beforeSave($insert) {//{{{
        if($insert){
            $this->created_at = date("Y-m-d H:i:s");
            $this->user_id    = Yii::$app->user->id;
        }
        return parent::beforeSave($insert);
    }//}}}



    //  获取对应游轮   
    public function getCruise(){
        return $this->hasOne(Cruise::className(), ['id' => 'cruise_id']);
    }

    // 获取对应图片
    public function getImage(){
        return  $this->hasOne(Image::className(),['product_id'=>'id'])->onCondition(['image.type'=>3,'image.status'=>1]);
    }
    
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app.cruise', 'ID'),
            'cruise_id' => Yii::t('app.cruise', 'Cruise ID'),
            'name' => Yii::t('app.cruise', 'Name'),
            'num' => Yii::t('app.cruise', 'Res Num'),
            'spend' => Yii::t('app.cruise', 'Spend'),
            'ceil' => Yii::t('app.cruise', 'Ceil'),
            'desc' => Yii::t('app.cruise', 'Desc'),
            'status' => Yii::t('app', 'Status'),
            'user_id' => Yii::t('app', 'User ID'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'open_time' => Yii::t('app', 'Open Time'),
            'en_name' => Yii::t('app', 'En Name'),
        ];
    }
}
